//
//  LBCropView.h
//  LBCropImagePage
//
//  Created by mac on 2024/6/2.
//

#import <UIKit/UIKit.h>
#import "LBCropConfig.h"

typedef NS_ENUM(NSInteger, kOriginAngle) {
    OriginAngleDeg0 = 0,
    OriginAngleDeg90 = 90,
    OriginAngleDeg180 = 180,
    OriginAngleDeg270 = 270,
};

NS_ASSUME_NONNULL_BEGIN

@interface LBCropView : UIView

///裁剪区域的边距
@property (nonatomic, assign) UIEdgeInsets margin;
///适配cropFrame 可裁剪的最小边距
@property (nonatomic, assign) UIEdgeInsets minMargin;

- (instancetype)initWithFrame:(CGRect)frame
                       margin:(UIEdgeInsets)margin
                       config:(nonnull LBCropConfig *)config;

- (instancetype)initWithFrame:(CGRect)frame
                       margin:(UIEdgeInsets)margin
                       config:(LBCropConfig *)config
                idleGridCount:(BMGridCount)idleGridCount
              rotateGridCount:(BMGridCount)rotateGridCount;

///获取同步的configure, 可用于保存当前的裁剪状态， 下一次打开恢复状态
- (LBCropConfig *)synConfigure;

/// 旋转
/// - Parameter angle: 单位：角度 基于``originAngle``, 范围 `-45° ~ 45°`
- (void)rotate:(CGFloat)angle;

/// 向左旋转 （`originAngle - 90°`）
- (void)rotateLeft:(BOOL)animated;

/// 向右旋转（`originAngle + 90°`）
- (void)rotateRight:(BOOL)animated;

/// 刷新裁剪比例
- (void)updateCropWHRatio:(CGFloat)cropWHRatio
            idleGridCount:(BMGridCount)idleGridCount
          rotateGridCount:(BMGridCount)rotateGridCount
                 animated:(BOOL)animated;

///显示旋转时的网格数
- (void)showRotateGrid:(BOOL)animated;

///隐藏旋转时的网格数
- (void)hideRotateGrid:(BOOL)animated;

///恢复 ：【调整角度 = 0】 + 【缩放比例= 1】 + 【中心点】
- (void)recoverWithAnimated:(BOOL)animated;

/// 同步裁剪
/// - Parameter compressScale: 压缩比例 默认为1， 即原图尺寸
- (UIImage *)cropWithCompressScale:(CGFloat)compressScale;

/// 异步裁剪
/// - Parameters:
///   - compressScale: 压缩比例默认为1 即原图尺寸
///   - cropDone: 完成回调
- (void)asyncCrop:(CGFloat)compressScale cropDone:(void (^)(UIImage *))cropDone;

@end

NS_ASSUME_NONNULL_END
